<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>todolist</h2>
      <input type="text" v-model="value" />
      <button v-on:click="add">添加</button>

      <ul>
        <li v-for="item in list">
          {{ item.name }} - <button v-on:click="remove(item.id)">删除</button>
        </li>
      </ul>
    </div>

    <script src="../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          value: "",
          list: [
            {
              name: "zhangsan",
              id: 1,
            },
            {
              name: "lisi",
              id: 2,
            },
          ],
        },
        methods: {
          add() {
            // console.log(this.value);
            this.list.push({
              name: this.value,
              id: new Date().getTime(),
            });
            this.value = "";
          },
          remove(id) {
            this.list = this.list.filter((item) => item.id !== id);
          },
        },
      });
    </script>
  </body>
</html>
